﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Security.Cryptography;

namespace Helper_Ji
{
    public static class Helper_MobileQQ
    {
        /// <summary>
        /// 登录QQ
        /// </summary>
        public static string QQLogin = "VER=1.4&CON=1&CMD=Login&SEQ=QQSeq&UIN=QQNumber&PS=QQPassword&M5=1&LG=0&LC=812822641C978097&GD=EX4RLS2GFYGR6T1R&CKE=\r\n";

        /// <summary>
        /// QQ验证码
        /// </summary>
        public static string QQYanZheng = "VER=1.4&CON=1&CMD=VERIFYCODE&SEQ=QQSeq&UIN=QQNumber&SID=&XP=C4CA4238A0B92382&SC=2&VC=YanZhengMa\r\n";

        /// <summary>
        /// 隐身
        /// </summary>
        public static string QQYinShen = " VER=1.4&CON=1&CMD=Change_Stat&SEQ=QQSeq&UIN=QQNumber&SID=&XP=C4CA4238A0B92382&ST=40\r\n";

        /// <summary>
        /// 离开
        /// </summary>
        public static string QQLiKai = " VER=1.4&CON=1&CMD=Change_Stat&SEQ=QQSeq&UIN=QQNumber&SID=&XP=C4CA4238A0B92382&ST=30\r\n";

        /// <summary>
        /// 在线
        /// </summary>
        public static string QQZaiXian = "VER=1.4&CON=1&CMD=Change_Stat&SEQ=QQSeq&UIN=QQNumber&SID=&XP=C4CA4238A0B92382&ST=10\r\n";

        /// <summary>
        /// 注销
        /// </summary>
        public static string QQZhuXiao = "VER=1.4&CON=1&CMD=Logout&SEQ=QQSeq&UIN=QQNumber&SID=&XP=C4CA4238A0B92382\r\n";

        /// <summary>
        /// 获取取QQ在线好友
        /// </summary>
        public static string QQZaiXianHaoYou = "VER=1.4&CON=1&CMD=Query_Stat2&SEQ=QQSeq&UIN=QQNumber&SID=&XP=C4CA4238A0B92382&CM=2&UN=0\r\n";

        /// <summary>
        /// 发送消息
        /// </summary>
        public static string QQSentMessage = "VER=1.4&CON=1&CMD=CLTMSG&SEQ=QQSeq&UIN=QQNumber&SID=&XP=C4CA4238A0B92382&UN=HaoYou&MG=Message\r\n";

        /// <summary>
        /// 查看好友资料
        /// </summary>
        public static string QQHaoYouZiLiao = "VER=1.4&CON=1&CMD=GetInfo&SEQ=QQSeq&UIN=QQNumber&SID=&XP=C4CA4238A0B92382&LV=2&UN=HaoYou\r\n";

        /// <summary>
        /// 加好友
        /// </summary>
        public static string QQJiaHaoYou = "VER=1.4&CON=1&CMD=AddToList&SEQ=QQSeq&UIN=QQNumber&SID=&XP=C4CA4238A0B92382&UN=HaoYou\r\n";

        /// <summary>
        /// 验证好友信息
        /// </summary>
        public static string QQYanZhengHaoYou = "VER=1.4&CON=1&CMD=Ack_AddToList&SEQ=QQSeq&UIN=QQNumber&SID=&XP=C4CA4238A0B92382&UN=HaoYou&CD=2&RS=YanZheng\r\n";

        /// <summary>
        /// 转换密码为MD5
        /// </summary>
        /// <param name="toCryString"></param>
        /// <returns></returns>
        public static string MD5(string toCryString)
        {
            System.Security.Cryptography.MD5CryptoServiceProvider hashmd5 = new System.Security.Cryptography.MD5CryptoServiceProvider();
            return BitConverter.ToString(hashmd5.ComputeHash(Encoding.Default.GetBytes(toCryString))).Replace("-", "").ToLower();
        }

    }

    public class QQ
    {
        public string QQNumber = null;
        public string QQPassword = null;
        public string QQZhuangTai = null;

        public enum QQzhuangtai
        {
            在线 = 1,
            隐身,
            离线
        }

        public void User(string number, string password)
        {
            this.QQNumber = number;
            this.QQPassword = password;
        }

        /// <summary>
        /// QQ登录
        /// </summary>
        /// <returns></returns>
        public Byte[] Login()
        {
            string SEQ = DateTime.Now.Ticks.ToString().Substring(7, 7);
            string PasswordMD5 = (this.QQPassword);
            string LoginString = Helper_MobileQQ.QQLogin.Replace("QQSeq", SEQ).Replace("QQNumber", this.QQNumber).Replace("QQPassword", PasswordMD5);
            return System.Text.Encoding.UTF8.GetBytes(LoginString);

        }

        /// <summary>
        /// 验证码
        /// </summary>
        /// <param name="yanzheng"></param>
        /// <returns></returns>
        public Byte[] YanZheng(string yanzheng)
        {
            string SEQ = DateTime.Now.Ticks.ToString().Substring(7, 7);
            string yz = Helper_MobileQQ.QQYanZheng.Replace("QQSeq", SEQ).Replace("QQNumber", this.QQNumber).Replace("YanZhengMa", yanzheng);
            return System.Text.Encoding.UTF8.GetBytes(yz);
        }

        /// <summary>
        /// 隐身
        /// </summary>
        /// <returns></returns>
        public Byte[] YinShen()
        {
            string SEQ = DateTime.Now.Ticks.ToString().Substring(7, 7);
            string ys = Helper_MobileQQ.QQYinShen.Replace("QQSeq", SEQ).Replace("QQNumber", this.QQNumber);
            return System.Text.Encoding.UTF8.GetBytes(ys);
        }

        /// <summary>
        /// 离开
        /// </summary>
        /// <returns></returns>
        public Byte[] LiKai()
        {
            string SEQ = DateTime.Now.Ticks.ToString().Substring(7, 7);
            string lk = Helper_MobileQQ.QQLiKai.Replace("QQSeq", SEQ).Replace("QQNumber", this.QQNumber);
            return System.Text.Encoding.UTF8.GetBytes(lk);
        }

        /// <summary>
        /// 在线
        /// </summary>
        /// <returns></returns>
        public Byte[] ZaiXian()
        {
            string SEQ = DateTime.Now.Ticks.ToString().Substring(7, 7);
            string zx = Helper_MobileQQ.QQZaiXian.Replace("QQSeq", SEQ).Replace("QQNumber", this.QQNumber);
            return System.Text.Encoding.UTF8.GetBytes(zx);
        }

        /// <summary>
        ///注销
        /// </summary>
        /// <returns></returns>
        public Byte[] ZhuXiao()
        {
            string SEQ = DateTime.Now.Ticks.ToString().Substring(7, 7);
            string zx = Helper_MobileQQ.QQZhuXiao.Replace("QQSeq", SEQ).Replace("QQNumber", this.QQNumber);
            return System.Text.Encoding.UTF8.GetBytes(zx);
        }

        /// <summary>
        /// 获取在线好友
        /// </summary>
        /// <param name="ZaiXianHaoYou"></param>
        /// <returns></returns>
        public Byte[] ZaiXianHaoYou()
        {
            string SEQ = DateTime.Now.Ticks.ToString().Substring(7, 7);
            string zxhy = Helper_MobileQQ.QQZaiXianHaoYou.Replace("QQSeq", SEQ).Replace("QQNumber", this.QQNumber);
            return System.Text.Encoding.UTF8.GetBytes(zxhy);
        }

        /// <summary>
        /// 发送消息
        /// </summary>
        /// <param name="SentMessage"></param>
        /// <returns></returns>
        public Byte[] SentMessage(string qqNumber, string message)
        {
            string SEQ = DateTime.Now.Ticks.ToString().Substring(7, 7);
            string sm = Helper_MobileQQ.QQSentMessage.Replace("QQSeq", SEQ).Replace("QQNumber", this.QQNumber).Replace("HaoYou", qqNumber).Replace("Message", message);
            return System.Text.Encoding.UTF8.GetBytes(sm);
        }

        /// <summary>
        /// 获取好友资料
        /// </summary>
        /// <param name="qqNumber"></param>
        /// <param name="message"></param>
        /// <returns></returns>
        public Byte[] HaoYouZiLiao(string qqNumber)
        {
            string SEQ = DateTime.Now.Ticks.ToString().Substring(7, 7);
            string sm = Helper_MobileQQ.QQHaoYouZiLiao.Replace("QQSeq", SEQ).Replace("QQNumber", this.QQNumber).Replace("HaoYou", qqNumber);
            return System.Text.Encoding.UTF8.GetBytes(sm);
        }

    }
}